package cn.dogger.easyboot.system.service.impl;


import cn.dogger.easyboot.common.exception.RollBackException;
import cn.dogger.easyboot.system.domain.bo.SysDeptBO;
import cn.dogger.easyboot.system.domain.dto.SysDeptDTO;
import cn.dogger.easyboot.system.domain.entity.SysDept;
import cn.dogger.easyboot.system.domain.vo.SysDeptDetail;
import cn.dogger.easyboot.system.domain.vo.SysDeptVO;
import cn.dogger.easyboot.system.mapper.SysDeptMapper;
import cn.dogger.easyboot.system.service.SysDeptService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
* 部门表
* @author dogger
* 2022-04-16
*/
@Service
public class SysDeptServiceImpl  extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {

         private final SysDeptMapper mapper;

         public SysDeptServiceImpl(SysDeptMapper mapper) {
            this.mapper = mapper;
         }
         
    @Override
    public List<SysDeptVO> page(SysDeptDTO dto) {
       // dto.setCreatedBy(TokenUtil.getLoginInfo().getUserId());
        List<SysDeptVO> list = mapper.list(dto);
        return list;
    }


    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void add(SysDeptBO bo) {
        SysDept entity = BeanUtil.copyProperties(bo, SysDept.class);
        mapper.insert(entity);
    }

    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void edit(SysDeptBO bo) {
        SysDept entity = BeanUtil.copyProperties(bo, SysDept.class);
        mapper.updateById(entity);
    }

    @Override
    public SysDeptDetail detailById(String id) {
       SysDept entity =  mapper.selectById(id);
        return BeanUtil.toBean(entity,SysDeptDetail.class);
    }

    @Override
    public void removeByIds(String[] ids) {
        List<String> list = Arrays.asList(ids);
        mapper.deleteBatchIds(list);
    }
}